#include "blockQueue.hpp"

void *Produce(void *args)
{
    BlockQueue<int> *bqueue = (BlockQueue<int> *)args;
    while (true)
    {
        int data = rand() % 100;
        cout << "productor: 生产一个数据, " << data << endl;
        bqueue->Push(data);
        sleep(1);
    }
    return nullptr;
}

void *Consume(void *args)
{
    BlockQueue<int>* bqueue = (BlockQueue<int>*)args;
    while(true)
    {
        int data;
        bqueue->Pop(&data);
        cout << "customer, 消费一个数据, " << data << endl;
        sleep(1);
    }
    return nullptr;
}

int main()
{
    srand((unsigned int)time(nullptr));
    BlockQueue<int> *bqueue = new BlockQueue<int>();
    pthread_t customer, productor;
    pthread_create(&productor, nullptr, Produce, (void *)bqueue);
    pthread_create(&customer, nullptr, Consume, (void *)bqueue);

    pthread_join(productor, nullptr);
    pthread_join(customer, nullptr);

    delete bqueue;
    return 0;
}